package com.best.developer.myarchitecturedemo.ui.activity;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.best.developer.myarchitecturedemo.R;
import com.best.developer.myarchitecturedemo.ui.fragment.GirlListFragment;
import com.best.developer.myarchitecturedemo.ui.fragment.ZhihuListFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {

    private List<Fragment> mFragmentList = new ArrayList<>();

    private ViewPager mViewPager = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {

        mFragmentList.add(new GirlListFragment());
        mFragmentList.add(new ZhihuListFragment());


        mViewPager = (ViewPager) findViewById(R.id.vp_home);
        mViewPager.setAdapter(new MainFragmentPagerAdapter(getSupportFragmentManager()));


        //初始化BottomNavigationBar
        BottomNavigationBar navigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
        navigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                mViewPager.setCurrentItem(position);
            }

            @Override
            public void onTabUnselected(int position) {

            }

            @Override
            public void onTabReselected(int position) {

            }
        });
        //添加两个点击图案
        //添加两个点击图案
        navigationBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite, "Girl"))
                .addItem(new BottomNavigationItem(R.drawable.ic_grade, "Zhihu"))
                .initialise();
        Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
        initToolbar(toolbar, false, R.string.app_name);

    }


    /**
     * viewpager 适配器
     */
    private class MainFragmentPagerAdapter extends FragmentPagerAdapter {

        private MainFragmentPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }
    }

}
